transform: Add optimization for common case
authorBenjamin Otte <otte@redhat.com>
Wed, 19 Feb 2020 23:02:19 +0000 (00:02 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 21 Feb 2020 17:19:16 +0000 (18:19 +0100)
Transforming identity by an other transform does not mean we need to
painstakingly apply the individual steps of other to construct a new
transform, it means we can just return other.

Or in math terms:
  I * B = B
so just return B.

gsk/gsktransform.c

index c8e0d321b74f4bd6a679f41b3648d062da9b7e15..df6cb63bdd41d36b180964986912c980d7ff9244 100644 (file)
@@ -1622,6 +1622,12 @@ gsk_transform_transform (GskTransform *next,
   if (other == NULL)
     return next;
 
+  if (gsk_transform_is_identity (next))
+    {
+      gsk_transform_unref (next);
+      return gsk_transform_ref (other);
+    }
+
   next = gsk_transform_transform (next, other->next);
   return other->transform_class->apply (other, next);
 }